package com.czg.designmode.prototype;

import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 长方形类
 *
 * @author chenzhigang
 */
@Slf4j
public class Rectangle implements Shape {
    @Override
    public Object clone() {
        Rectangle rectangle = null;
        try {
            rectangle = (Rectangle) super.clone();
        } catch (CloneNotSupportedException e) {
            log.error("克隆长方形失败：" + e.getMessage(), e);
        }
        return rectangle;
    }

    @Override
    public BigDecimal countArea() {
        System.out.println("请输入长方形的长：");
        Scanner lengthInput = new Scanner(System.in);
        BigDecimal length = lengthInput.nextBigDecimal();
        System.out.println("请输入长方形的宽：");
        Scanner wideInput = new Scanner(System.in);
        BigDecimal wide = wideInput.nextBigDecimal();
        return length.multiply(wide).setScale(2, BigDecimal.ROUND_HALF_UP);
    }
}
